all: Makefile document

targetdoc=answers.pdf

dias= 
svgs=
pngs=
pdfs=
dots=

# "Images class. Replace extensions with .image, so it is easily transferable to
# eps, pdf, png or whatever pictures later
images=$(figs:.fig=.image) $(dias:.dia=.image) $(pngs:.png=.image) $(svgs:.svg=.image) $(dots:.dot=.image)

epsimages=$(images:.image=.eps)
pdfimages=$(images:.image=.pdf) $(pdfs) 


pdfimgs: Makefile $(pdfimages)

commit: document
	svn commit

document: Makefile $(targetdoc)
	evince $(targetdoc)
	
%.ps: %.dvi Makefile
	dvips $<

%.dvi: %.tex Makefile
	latex $<
	latex $<
	latex $<

%.aux: %.tex
	pdflatex -halt-on-error $< > auxlog.txt

#uncomment for cite's

#%.bbl: %.aux
#	bibtex $<
#
#%.pdf: %.tex %.bbl pdfimgs Makefile
#	pdflatex -halt-on-error $< > pdflog.txt
#	echo "second pass for ensuring correct index..."
#	echo "log of first pass will be overwritten..."
#	pdflatex -halt-on-error $< > pdflog.txt

#comment for cite's

%.pdf: %.tex pdfimgs Makefile
	pdflatex -halt-on-error $< > pdflog.txt
	echo "second pass for ensuring correct index..."
	echo "log of first pass will be overwritten..."
	pdflatex -halt-on-error $< > pdflog.txt

%.eps: %.fig Makefile 
	fig2dev -L eps $< $@

%.pdf: %.fig Makefile 
	fig2dev -L pdf $< $@

%.jpg: %.fig Makefile 
	fig2dev -L jpg $< $@

%.png: %.fig Makefile 
	fig2dev -L png $< $@

%.eps: %.svg Makefile
	inkscape --file=$< --export-eps=$@

%.pdf: %.dot Makefile
	dot -Tpdf $< -o $@

%.png: %.dia Makefile
	dia -e $@ $<

%.eps: %.png Makefile
	convert $< $@

%.eps: %.dia Makefile
	dia -e $@ $<

%.eps: %.png Makefile
	convert $< $@

%.pdf: %.eps Makefile
	cat $< | grep -v nan | epstopdf --filter > $@

clean:
	rm -fr $(epsimages) answers.pdf *.aux *.bbl *.blg *.log *.toc *.bak *.out 
	rm *~

maintainerclean: clean
	rm -fr $(targetdoc)

.PHONY:
	clean maintainerclean document pdfimgs
